package models

import "sport_booking/dao"

type Email struct {
	Type    string `json:"type"`
	Date    string `json:"date"`
	Address string `json:"address"`
	Title   string `json:"title"`
	Body    string `json:"body"`
	UUID    string `json:"uuid"`
}

/*
添加邮件信息
*/
func AddEmailInfo(email *Email) (int64, error) {
	sqlStr := "INSERT INTO bk_emails (email_type,email_date,email_address,email_title,email_body,user_uuid) VALUES (?,?,?,?,?,?)"
	result, err := dao.DB.Exec(sqlStr, email.Type, email.Date, email.Address, email.Title, email.Body, email.UUID)
	if err != nil {
		return 0, err
	}
	return result.RowsAffected()
}

/*
根据uuid获取邮件信息列表,一次10行
*/
func GetEmailInfoByUUID(uuid string, page int) (*Email, error) {
	var email *Email
	sqlStr := "SELECT email_type,email_date,email_address,email_title,email_body FROM bk_emails WHERE user_uuid=? LIMIT ?,10"
	err := dao.DB.Select(email, sqlStr, uuid, page*10)
	if err != nil {
		return nil, err
	}
	return email, nil
}
